﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Easy_1700_CountStudents
{
    class MainProjecet
    {
        static void Main(string[] args)
        {
            Console.WriteLine(CountStudents(new int[] { 1, 1, 1, 0, 0, 1 }, new int[] { 1, 0, 0, 0, 1, 1 }));
            Console.ReadKey();
        }
        public static int CountStudents(int[] students, int[] sandwiches)
        {
            //根据题意进行模拟+队列辅助
            Queue<int> que = new Queue<int>(students);
            Queue<int> food = new Queue<int>(sandwiches);
            int count = 0;
            int stu = 0;
            int f = 0;
            while (students.Length > 0 && food.Count > 0)
            {
                if (count >= que.Count) break;
                stu = que.Dequeue();
                f = food.Peek();

                if (stu == f)
                {
                    count = 0;
                    food.Dequeue();
                }
                else
                {
                    count++;
                    que.Enqueue(stu);
                }
            }
            return que.Count;
        }
    }
}
